home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / System / PBGetInfo INIT / SF Lock Test.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-28  |  5.4 KB  |  320 lines  |  [TEXT/KAHL]

  1. #include <Traps.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5.  
  6. #include "PBGetInfo.h"
  7.  
  8.  
  9.  
  10. main()
  11. {
  12. char         *moof,installed;
  13. Handle         myCodeRes;
  14. Handle        lockStatusHandle;
  15. long        theSize;
  16. SysEnvRec    theWorld;
  17. CInfoPBRec    myPBRec;
  18. char        volName[256];
  19. char        tempString[256];
  20. int            errCode;
  21. int            vRefNum;
  22. long        freeBytes;
  23. long        oldTrapAddress;
  24.  
  25.     installed = FALSE;
  26.     
  27.     errCode = GetVInfo(0,volName,&vRefNum,&freeBytes);
  28.     
  29.     if (errCode != noErr)
  30.         SysBeep(1);
  31.     
  32.     else
  33.     {
  34.         errCode = SysEnvirons(1,&theWorld);
  35.         
  36.         if (errCode != noErr)
  37.         {
  38.             SysBeep(1);
  39.             SysBeep(1);
  40.         }
  41.         
  42.         else
  43.         {
  44.             volName[0] = 0;
  45.             
  46.             myPBRec.dirInfo.ioCompletion = 0L;
  47.             myPBRec.dirInfo.ioNamePtr = (StringPtr) volName;
  48.             myPBRec.dirInfo.ioVRefNum = theWorld.sysVRefNum;
  49.             myPBRec.dirInfo.ioFDirIndex = -1;
  50.             myPBRec.dirInfo.ioDrDirID = 0L;
  51.             
  52.             errCode = PBGetCatInfo(&myPBRec,FALSE);
  53.             
  54.             if (errCode != noErr)
  55.             {
  56.                 SysBeep(1);
  57.                 SysBeep(1);
  58.                 SysBeep(1);
  59.             }
  60.             
  61.             else
  62.             {
  63.                 myCodeRes = GetNamedResource('RoyW',patchName);
  64.             
  65.                 if(myCodeRes == nil)
  66.                 {
  67.                     SysBeep(1);
  68.                     SysBeep(1);
  69.                     SysBeep(1);
  70.                     SysBeep(1);
  71.                 }
  72.                 
  73.                 else
  74.                 {
  75.                     theSize = GetHandleSize(myCodeRes);
  76.                     for(moof=*myCodeRes;theSize>0 && strcmp(moof,"Moof")!=EQSTR;moof++,theSize--);
  77.                     
  78.                     if (theSize <= 0L || strcmp(moof,"Moof")!=EQSTR)
  79.                     {
  80.                         SysBeep(1);
  81.                         SysBeep(1);
  82.                         SysBeep(1);
  83.                         SysBeep(1);
  84.                         SysBeep(1);
  85.                     }
  86.                     
  87.                     else
  88.                     {
  89.                         oldTrapAddress = NGetTrapAddress((int) (_HFSDispatch - 0xA000),OSTrap);
  90.                         
  91.                         moof += 4L;
  92.                         *((long *) moof) = NGetTrapAddress((int) (_HFSDispatch - 0xA000),OSTrap);
  93.                         moof += 4L;
  94.                         *((int *) moof) = theWorld.sysVRefNum;
  95.                         moof += 2L;
  96.                         *((int *) moof) = vRefNum;
  97.                         moof += 2L;
  98.                         *((long *) moof) = myPBRec.dirInfo.ioDrDirID;
  99.                         moof += 4L;
  100.                         *((long *) moof) = myPBRec.dirInfo.ioDrParID;
  101.                         
  102.                         HLock(myCodeRes);
  103.                         
  104.                         NSetTrapAddress((long) StripAddress(*myCodeRes),(_HFSDispatch - 0xA000),OSTrap);
  105.                         
  106.                         
  107.                         strcpy(tempString,LOCKMESSAGE);
  108.                         
  109.                         myPBRec.dirInfo.ioCompletion = 0L;
  110.                         myPBRec.dirInfo.ioNamePtr = (StringPtr) LOCKMESSAGE;
  111.                         myPBRec.dirInfo.ioVRefNum = 0;
  112.                         myPBRec.dirInfo.ioFDirIndex = 0;
  113.                         myPBRec.dirInfo.ioDrDirID = 0L;
  114.                         
  115.                         errCode = PBGetCatInfo(&myPBRec,FALSE);
  116.                         
  117.                         if (errCode == noErr)
  118.                             installed = TRUE;
  119.                         
  120.                         doDirStuff();
  121.                         
  122.                         NSetTrapAddress(oldTrapAddress,(_HFSDispatch - 0xA000),OSTrap);
  123.                         ReleaseResource(myCodeRes);
  124.                     }
  125.                 }
  126.             }
  127.         }
  128.     }
  129. }
  130.  
  131.  
  132.  
  133.  
  134. doDirStuff()
  135. {
  136. int                vRefNum;
  137. SFReply            mySFReply;
  138. Point            topLeftPt;
  139. SFTypeList        fileTypes;
  140. union    {
  141.         char    name[5];
  142.         long    num;
  143.         } fType;
  144.  
  145.     do
  146.     {
  147.         PrintDir();
  148.         
  149.         topLeftPt.h = 45;
  150.         topLeftPt.v = 45;
  151.         fileTypes[0] = 'APPL';
  152.         
  153.         SFGetFile(topLeftPt,"\p",0L,-1,&fileTypes,0L,&mySFReply);
  154.         
  155.         if (mySFReply.good)
  156.         {
  157.             PtoCstr((char *) mySFReply.fName);
  158.             printf("File selected: %s\n",mySFReply.fName);
  159.             
  160.             fType.num = mySFReply.fType;
  161.             fType.name[4] = 0;
  162.             printf("File type: %s\n",fType.name);
  163.         }
  164.         else
  165.             printf("SFGetFile returns error\n");
  166.         
  167.         More();
  168.         
  169.         
  170.         
  171.     } while (mySFReply.good);
  172. }
  173.  
  174.  
  175.  
  176.  
  177. More()
  178. {
  179. char    ch;
  180.  
  181.     printf("\n<more>");
  182.     ch = getchar();
  183. }
  184.  
  185.  
  186.  
  187.  
  188. PrintDir()
  189. {
  190. int                    errCode,index;
  191. char                vName[256];
  192. HParamBlockRec        myPB;
  193.  
  194.     printf("\n");
  195.     printf("Directory Contents:\n");
  196.     
  197.     index = 1;
  198.     
  199.     do
  200.     {
  201.         vName[0] = 0;
  202.         
  203.         myPB.fileParam.ioCompletion = 0L;
  204.         myPB.fileParam.ioNamePtr = (StringPtr) &vName;
  205.         myPB.fileParam.ioVRefNum = -SFSaveDisk;
  206.         myPB.fileParam.ioFVersNum = 0;
  207.         myPB.fileParam.ioFDirIndex = index++;
  208.         myPB.fileParam.ioDirID = CurDirStore;
  209.         
  210.         errCode = PBHGetFInfo(&myPB,FALSE);
  211.         
  212.         if (errCode==noErr)
  213.         {
  214.             PtoCstr(vName);
  215.             printf("%s\n",vName);
  216.         }
  217.         
  218.     } while (errCode==noErr);
  219.     
  220.     if (errCode != fnfErr)
  221.         printf("*** PBGetFInfo error #%d ***\n",errCode);
  222.     
  223.     More();
  224. }
  225.  
  226.  
  227.  
  228.  
  229. SetPath(pathName)
  230. StringPtr    pathName;
  231. {
  232. int                errCode;
  233. WDPBRec            myWDPB;
  234.  
  235.     printf("\n");
  236.     
  237.     PrintCurrentDir();
  238.     
  239.     printf("Changing default volume to '%s'\n",pathName);
  240.     CtoPstr((char *) pathName);
  241.     
  242.     myWDPB.ioCompletion = 0L;
  243.     myWDPB.ioNamePtr = pathName;
  244.     myWDPB.ioVRefNum = -SFSaveDisk;
  245.     myWDPB.ioWDDirID = 0L;
  246.     
  247.     errCode = PBHSetVol(&myWDPB,FALSE);
  248.     
  249.     if (errCode!=noErr)
  250.         printf("*** PBHSetVol Error #%d ***\n",errCode);
  251.     
  252.     else
  253.     {
  254.         myWDPB.ioCompletion = 0L;
  255.         errCode = PBHGetVol(&myWDPB,FALSE);
  256.         
  257.         if (errCode!=noErr)
  258.             printf("*** PBHGetVol Error #%d ***\n",errCode);
  259.         else
  260.         {
  261.             CurDirStore = myWDPB.ioWDDirID;
  262.             SFSaveDisk = -myWDPB.ioVRefNum;
  263.             
  264.             PrintCurrentDir();
  265.         }
  266.     }
  267.         
  268.     
  269.     More();
  270.     
  271.     return(errCode);
  272. }
  273.  
  274.  
  275.  
  276.  
  277. PrintCurrentDir()
  278. {
  279. WDPBRec        myWDPB;
  280. CInfoPBRec    myCPB;
  281. int            vRefNum;
  282. int            errCode;
  283. char        tempString[256],pathName[256];
  284. long        theDir;
  285.  
  286.     pathName[0] = 0;
  287.     
  288.     theDir = CurDirStore;
  289.     
  290.     do
  291.     {
  292.         tempString[0] = 0;
  293.         
  294.         myCPB.dirInfo.ioCompletion = 0L;
  295.         myCPB.dirInfo.ioNamePtr = (StringPtr) &tempString;
  296.         myCPB.dirInfo.ioVRefNum = -SFSaveDisk;
  297.         myCPB.dirInfo.ioFDirIndex = -1;
  298.         myCPB.dirInfo.ioDrDirID = theDir;
  299.         
  300.         errCode = PBGetCatInfo(&myCPB,FALSE);
  301.         
  302.         if (errCode!=noErr)
  303.             printf("*** PBGetCatInfo Error #%d ***\n",errCode);
  304.         
  305.         else
  306.         {
  307.             PtoCstr(tempString);
  308.             
  309.             theDir = myCPB.dirInfo.ioDrParID;
  310.             
  311.             strcat(tempString,":");
  312.             strcat(tempString,pathName);
  313.             strcpy(pathName,tempString);
  314.         }
  315.         
  316.     } while (myCPB.dirInfo.ioDrParID>=2 && errCode==noErr);
  317.         
  318.     if (errCode == noErr)
  319.         printf("Full pathname: '%s'\n",pathName);
  320. }